package com.yitongmao.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yitongmao.bean.TuiKuanBean;
import com.yitongmao.yitmfruit.R;

import java.util.List;

/*
* 作者：梁伟航 on 2017/7/31 18:34
* 类的用途：
*/
public class YiWanChengAdapter extends BaseAdapter{
    private Context context;
    private List<TuiKuanBean.OrderListBean> orderList;
    public YiWanChengAdapter(Context context, List<TuiKuanBean.OrderListBean> orderList) {
        this.context=context;
        this.orderList=orderList;
    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int position) {
        return orderList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.tuikuan, null);
            //付款状态
            viewHolder.mFuKuanZhuangTai = (TextView) convertView.findViewById(R.id.mFuKuanZhuangTai);
            //图片
            viewHolder.homelistimage = (ImageView) convertView.findViewById(R.id.homelistimage);
            //title
            viewHolder.homelistTitle = (TextView) convertView.findViewById(R.id.homelistTitle);
            //价钱
            viewHolder.homelistprice = (TextView) convertView.findViewById(R.id.homelistprice);
            viewHolder.mSumPrice = (TextView) convertView.findViewById(R.id.mSumPrice);

            //再次购买
            viewHolder.mMyAgainBuy = (Button) convertView.findViewById(R.id.mMyAgainBuy);
            //申请退款
            viewHolder.mMyApplyRefund = (Button) convertView.findViewById(R.id.mMyApplyRefund);
            //去付款
            viewHolder.mMyGoPay = (Button) convertView.findViewById(R.id.mMyGoPay);
            //取消订单
            viewHolder.mMyCanCle = (Button) convertView.findViewById(R.id.mMyCanCle);
            convertView.setTag(viewHolder);//绑定ViewHolder对象
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        int number = orderList.get(position).orderGoods.get(0).number;
        double sum = orderList.get(position).orderGoods.get(0).tradePrice * number;
        viewHolder.mSumPrice.setText("￥"+sum+"");
        viewHolder.mFuKuanZhuangTai.setText(orderList.get(position).stateName);
        viewHolder.homelistTitle.setText(orderList.get(position).orderGoods.get(0).title);
        Glide.with(context).load(orderList.get(position).orderGoods.get(0).goodsThumb).into(viewHolder.homelistimage);
        viewHolder.homelistprice.setText(orderList.get(position).orderGoods.get(0).tradePrice + "");
        for (int i=0;i<orderList.size();i++){
            if (orderList.get(i).state.equals("04")){
                //取消订单
                viewHolder.mMyCanCle.setVisibility(View.GONE);
                //去付款
                viewHolder.mMyGoPay.setVisibility(View.GONE);
                //再次购买
                viewHolder.mMyAgainBuy.setVisibility(View.GONE);
                //申请退款
                viewHolder.mMyApplyRefund.setVisibility(View.GONE);
            }
        }
        return convertView;
    }
    class ViewHolder {
        public TextView mFuKuanZhuangTai;
        public TextView homelistTitle;
        public ImageView homelistimage;
        public TextView homelistprice;
        public Button mMyAgainBuy;
        public Button mMyApplyRefund;
        public Button mMyGoPay;
        public Button mMyCanCle;
        public TextView mSumPrice;
    }
}
